const mongoose = require("mongoose")

mongoose.connect("mongodb://localhost:27017/twoone")
    .then(() => {
        console.log("ok");
    })
    .catch(err => {
        console.log(err);
    })

const chexiSchema = new mongoose.Schema({
    name: String,
    from: String
})

const typeSchema = new mongoose.Schema({
    name: String,
    cid: {
        type: mongoose.Types.ObjectId,
        ref: "chexi"
    }
})

const carSchema = new mongoose.Schema({
    name: String,
    img: String,
    price: Number,
    tid:{
        type:mongoose.Types.ObjectId,
        ref:"type"
    }
})

const chexiModel = mongoose.model("chexi", chexiSchema, "chexi")
const typeModel = mongoose.model("type", typeSchema, "type")
const carModel = mongoose.model("car", carSchema, "car")

module.exports = {
    chexiModel,
    typeModel,
    carModel
}